/*-------------------------------------------------------------------------
 * 版权所有：	黑客马拉松
 * 作者：		罗毅
 * 联系方式：	whluoyi@gmail.com
 * 创建时间：	2016/10/29 11:23:16
 * 版本号：		v1.0
 * 用途描述：	控制器
 *  -------------------------------------------------------------------------*/

namespace SuperMarieApi.App.Controllers.V1
{
    using SuperMarieApi.App.Controllers.Biz;
    using SuperMarieApi.App.Controllers.Bll;
    using SuperMarieApi.App.Controllers.Entity;
    using SuperMarieApi.App.Controllers.Framework.DataAccess;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Web.Http;

    [Serializable()]
    public class MyFileEntity
    {
        private String _FileUrl = null;
        private String _FilePath = null;
        private String _Filebase64 = null;


        /// <summary> 
        /// 文件路径 
        /// </summary> 
        [DataMapping("FileUrl", DbType.String)]
        public String FileUrl
        {
            get { return this._FileUrl; }
            set { this._FileUrl = value; }
        }



        /// <summary> 
        /// 文件物理路径 
        /// </summary> 
        [DataMapping("FilePath", DbType.String)]
        public String FilePath
        {
            get { return this._FilePath; }
            set { this._FilePath = value; }
        }

        /// <summary> 
        /// 文件base64 
        /// </summary> 
        [DataMapping("Filebase64", DbType.String)]
        public String Filebase64
        {
            get { return this._Filebase64; }
            set { this._Filebase64 = value; }
        }

    }
    public class MyFileToolController : ApiController
    {
        public static List<MyFileEntity> Model = new List<MyFileEntity>();

        // GET api/MyImg
        public IEnumerable<MyFileEntity> Get()
        {
            return Model;
        }

        //保存前端摄像头base64文件
        // POST api/v1/MyFileTool
        public HttpResponseMessage Post([FromBody] MyFileEntity value)
        {
            int fileid = 0;
            List<string> files = AppRootBiz.Base64StringToImage(value.Filebase64);
            if (files.Count == 2)
            {
                MyImgEntity entity = new MyImgEntity();
                entity.FilePath = files[0];
                entity.FileUrl = files[1];
                entity.Filebase64 = value.Filebase64;
                entity.AddTime = DateTime.Now;
                fileid = MyImgBiz.InsertMyImgObj(entity);
            }
            string json = "{_MyImg_ID:" + fileid + "}";
            return new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content =
                    new StringContent(
                    json,
                    System.Text.Encoding.UTF8,
                    "application/json")
            };
        }

    }
}